﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Markup;

namespace RStein.PosterousReader.WP.UI
{
  
  public class ButtonEx : Button
  {

    
    public ButtonEx()
      : base()
    {

      DefaultStyleKey = typeof(Button);
    }

    public static readonly DependencyProperty CommandProperty = 
      DependencyProperty.Register("Command", typeof(ICommand), typeof(ButtonEx), new PropertyMetadata(null));
    
    public ICommand Command
    {
        get 
        {
          return (ICommand)GetValue(CommandProperty); 
        }
        set 
        {
          SetValue(CommandProperty, value); 
        }
    }


    public static readonly DependencyProperty CommandParameterProperty =
      DependencyProperty.Register("CommandParameter", typeof(Object), typeof(ButtonEx), new PropertyMetadata(null));

    public Object CommandParameter
    {
      get
      {
        return (Object) GetValue(CommandParameterProperty);
      }
      set
      {
        SetValue(CommandParameterProperty, value);
      }
    }
    

    protected override void OnClick()
    {
      base.OnClick();
      
      if (Command != null && Command.CanExecute(CommandParameter))
      {
        Command.Execute(CommandParameter);
      }
      
    }

    
  }
}
